#include<stdio.h>

int arr[10010]={0};

int main()
{
    int n,m;
    int max = 0;
    int end = 0;
    scanf("%d%d",&n,&m);
    while(m--)
    {
        int space;
        int light;
        scanf("%d%d",&space,&light);
        if(space > end)
        {
            end = space;
        }
        arr[space]+=light;
    }
    for(int i =1;i<=end;i++)
    {
        int count = 0;
        for(int j=0;j<n;j++)
        {
            count += arr[i+j];
        }
        if(count>max)
        {
            max = count;
        }
    }
    printf("%d",max);
    return 0;
}